import Vue from 'vue'
import App from './components/App.vue'
import VueRouter from 'vue-router'
import routes from './router/index.js'
import store from "./store/index.js"
import 'swiper/dist/css/swiper.css';
import VueLazyLoad from 'vue-lazyload'
Vue.use(VueLazyLoad,{
    // error:'static/error.png',
    // loading:'static/loading.png'
})

Vue.use(VueRouter)

Vue.config.productionTip = false;

const router = new VueRouter({
  routes
});

router.beforeEach((to, from, next) => {
  if (to.path == "/") {
    store.commit("homeTabIndexChange", 0)
  }

  if (to.path == "/category") {
    store.commit("homeTabIndexChange", 1)
  }

  if (to.path == "/groupbuy") {
    store.commit("homeTabIndexChange", 2);
    next("/groupbuy/zero");
  }

  if (to.path == "/cart") {
    store.commit("homeTabIndexChange", 3)
  }

  if (to.path == "/login") {
    store.commit("homeTabIndexChange", 4)
  }
  next();
});
// router.afterEach((to, from, next) => {

//   if (from.path == "/") {
//     if (to.path == "/goodsdetails") {
//       this.$refs.gooddetail.scrollTop = 0;
//     }
//   }
// });

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
